package com.tjtt.gwm.dao.impl;

import java.util.List;
import java.util.Map;

import org.hibernate.Query;

import com.tjtt.gwm.dao.GuanxianDao;
import com.tjtt.gwm.dao.SearchDao;
import com.tjtt.gwm.dao.TongjiDao;
import com.tjtt.tdm.base.BaseHibernateDao;
import com.tjtt.tdm.base.PageResult;

public class TongjiDaoImpl extends BaseHibernateDao implements TongjiDao {
	
	public PageResult tongjiJingtaisj(Map filterMap){
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		String fieldname = filterMap.get("fieldname").toString();
		String gxids = "";
		if (filterMap.get("gxids")!=null){
			gxids = filterMap.get("gxids").toString().replace("gx", "").replace("all", "");
		}
		String t1strWhere = "";
		String t3strWhere = "";
		if (!gxids.equals("")){
			String stridsinfo = "";
			String[] arraygxids = gxids.split(",");
			for(int i=0;i<arraygxids.length;i++){
				if (!arraygxids[i].equals(""))
				{
					stridsinfo+="'"+arraygxids[i]+"',";
				}
			}
			if (stridsinfo.length()>0){
				stridsinfo = stridsinfo.substring(0,stridsinfo.length()-1);
			}
			t1strWhere = " and t1.pipelineno in ("+stridsinfo+")";
			t3strWhere = " and t3.pipelineno in ("+stridsinfo+")";
		}
		
		String guanxianlistsql = "";
		if (fieldname.indexOf("t1")>=0){
			guanxianlistsql = fieldname+"="+fieldname.replace("t1", "t3");
		}
		else if (fieldname.indexOf("t2")>=0){
			guanxianlistsql = fieldname+"="+fieldname.replace("t2", "t4");
		}
		
		queryString.append("select "+fieldname+",(select wm_concat(pipelineno) from PTEM_PIPELINE t3 " +
				"left join PTEM_PROJECT_INFO t4 on t3.projectno = t4.projectno " +
				"where "+guanxianlistsql+t3strWhere+"  and rownum<100) as pipelinenos," +
				"count("+fieldname+") as vcount from PTEM_PIPELINE t1 " +
				"left join PTEM_PROJECT_INFO t2 on t1.projectno=t2.projectno " +
				"where "+fieldname+" is not null  "+t1strWhere+" group by "+fieldname+" ");
		countString.append("select count(*) from ("+queryString+") t ");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	
	public List tongjiJingtaisjpic(Map filterMap){
		StringBuffer queryString = new StringBuffer();
		String fieldname = filterMap.get("fieldname").toString();
		String gxids = "";
		if (filterMap.get("gxids")!=null){
			gxids = filterMap.get("gxids").toString().replace("gx", "").replace("all", "");
		}
		String t1strWhere = "";
		String t3strWhere = "";
		if (!gxids.equals("")){
			String stridsinfo = "";
			String[] arraygxids = gxids.split(",");
			for(int i=0;i<arraygxids.length;i++){
				if (!arraygxids[i].equals(""))
				{
					stridsinfo+="'"+arraygxids[i]+"',";
				}
			}
			if (stridsinfo.length()>0){
				stridsinfo = stridsinfo.substring(0,stridsinfo.length()-1);
			}
			t1strWhere = " and t1.pipelineno in ("+stridsinfo+")";
			t3strWhere = " and t3.pipelineno in ("+stridsinfo+")";
		}
		
		String guanxianlistsql = "";
		if (fieldname.indexOf("t1")>=0){
			guanxianlistsql = fieldname+"="+fieldname.replace("t1", "t3");
		}
		else if (fieldname.indexOf("t2")>=0){
			guanxianlistsql = fieldname+"="+fieldname.replace("t2", "t4");
		}
		
		queryString.append("select "+fieldname+",(select wm_concat(pipelineno) from PTEM_PIPELINE t3 " +
				"left join PTEM_PROJECT_INFO t4 on t3.projectno = t4.projectno " +
				"where "+guanxianlistsql+t3strWhere+"  and rownum<100 ) as pipelinenos," +
				"count("+fieldname+") as vcount from PTEM_PIPELINE t1 " +
				"left join PTEM_PROJECT_INFO t2 on t1.projectno=t2.projectno " +
				"where "+fieldname+" is not null "+t1strWhere+" group by "+fieldname+" ");
		Query query = getSession().createSQLQuery(queryString.toString());
		return query.list();
	}
	
	public PageResult tongjiYalijz(Map filterMap){
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		String fieldname = filterMap.get("fieldname").toString();
		if (fieldname.equals("zhanxiangyljz")){
			String zxids = "";
			String strWhere = "";
			if (filterMap.get("zxids")!=null){
				zxids = filterMap.get("zxids").toString().replace("zx", "").replace("all", "");
			}
			if (!zxids.equals("")){
				String stridsinfo = "";
				String[] arraygxids = zxids.split(",");
				for(int i=0;i<arraygxids.length;i++){
					if (!arraygxids[i].equals(""))
					{
						stridsinfo+="'"+arraygxids[i]+"',";
					}
				}
				if (stridsinfo.length()>0){
					stridsinfo = stridsinfo.substring(0,stridsinfo.length()-1);
				}
				strWhere = " and pipeno in ("+stridsinfo+")";
			}
			queryString.append(" select PRESSURELEVEL,(select wm_concat(pipelineno) " +
					"from PTEM_STATION t2 where t1.PRESSURELEVEL = t2.PRESSURELEVEL "+strWhere+"  and rownum<100) as pipelinenos," +
					"count(PRESSURELEVEL) as vcount from PTEM_STATION t1 " +
					"where PRESSURELEVEL is not null "+strWhere+" group by PRESSURELEVEL");
			countString.append("select count(*) from ("+queryString+") t ");
			return searchBySQL(countString.toString(),queryString.toString(),filterMap);
		}
		else if (fieldname.equals("famenyljz")){
			String fmids = "";
			String strWhere = "";
			if (filterMap.get("fmids")!=null){
				fmids = filterMap.get("fmids").toString().replace("all", "");
			}
			if (!fmids.equals("")){
				String stridsinfo = "";
				String[] arraygxids = fmids.split(",");
				for(int i=0;i<arraygxids.length;i++){
					if (!arraygxids[i].equals(""))
					{
						stridsinfo+="'"+arraygxids[i]+"',";
					}
				}
				if (stridsinfo.length()>0){
					stridsinfo = stridsinfo.substring(0,stridsinfo.length()-1);
				}
				//strWhere = " and PIPENO in ("+stridsinfo+")";
				strWhere = " and VALVENO in ("+stridsinfo+")";
			}
			queryString.append(" select PRESSURELEVEL,(select wm_concat(pipelineno) " +
					"from PTEM_VALVE t2 where t1.PRESSURELEVEL = t2.PRESSURELEVEL "+strWhere+"  and rownum<100 ) as pipelinenos," +
					"count(PRESSURELEVEL) as vcount from PTEM_VALVE t1 " +
					"where PRESSURELEVEL is not null "+strWhere+" group by PRESSURELEVEL");
			countString.append("select count(*) from ("+queryString+") t ");
			return searchBySQL(countString.toString(),queryString.toString(),filterMap);
		}
		else{
			String gxids = "";
			String strWhere = "";
			if (filterMap.get("gxids")!=null){
				gxids = filterMap.get("gxids").toString().replace("gx", "").replace("all", "");
			}
			if (!gxids.equals("")){
				String stridsinfo = "";
				String[] arraygxids = gxids.split(",");
				for(int i=0;i<arraygxids.length;i++){
					if (!arraygxids[i].equals(""))
					{
						stridsinfo+="'"+arraygxids[i]+"',";
					}
				}
				if (stridsinfo.length()>0){
					stridsinfo = stridsinfo.substring(0,stridsinfo.length()-1);
				}
				strWhere = " and pipelineno in ("+stridsinfo+")";
			}
			queryString.append(" select PRESSURELEVEL,(select wm_concat(pipelineno) " +
					"from PTEM_PIPELINE t2 where t1.PRESSURELEVEL = t2.PRESSURELEVEL "+strWhere+"  ) as pipelinenos," +
					"count(PRESSURELEVEL) as vcount from PTEM_PIPELINE t1 " +
					"where PRESSURELEVEL is not null "+strWhere+" group by PRESSURELEVEL");
			countString.append("select count(*) from ("+queryString+") t ");
			return searchBySQL(countString.toString(),queryString.toString(),filterMap);
			
		}
	}
	
	public List tongjiYalijzpic(Map filterMap){
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		String fieldname = filterMap.get("fieldname").toString();
		if (fieldname.equals("zhanxiangyljz")){
			String zxids = "";
			String strWhere = "";
			if (filterMap.get("zxids")!=null){
				zxids = filterMap.get("zxids").toString().replace("zx", "").replace("all", "");
			}
			if (!zxids.equals("")){
				String stridsinfo = "";
				String[] arraygxids = zxids.split(",");
				for(int i=0;i<arraygxids.length;i++){
					if (!arraygxids[i].equals(""))
					{
						stridsinfo+="'"+arraygxids[i]+"',";
					}
				}
				if (stridsinfo.length()>0){
					stridsinfo = stridsinfo.substring(0,stridsinfo.length()-1);
				}
				strWhere = " and pipeno in ("+stridsinfo+")";
			}
			queryString.append(" select PRESSURELEVEL,(select wm_concat(pipelineno) " +
					"from PTEM_STATION t2 where t1.PRESSURELEVEL = t2.PRESSURELEVEL "+strWhere+"  ) as pipelinenos," +
					"count(PRESSURELEVEL) as vcount from PTEM_STATION t1 " +
					"where PRESSURELEVEL is not null "+strWhere+" group by PRESSURELEVEL");
			Query query = getSession().createSQLQuery(queryString.toString());
			return query.list();
		}
		else if (fieldname.equals("famenyljz")){
			String fmids = "";
			String strWhere = "";
			if (filterMap.get("fmids")!=null){
				fmids = filterMap.get("fmids").toString().replace("all", "");
			}
			if (!fmids.equals("")){
				String stridsinfo = "";
				String[] arraygxids = fmids.split(",");
				for(int i=0;i<arraygxids.length;i++){
					if (!arraygxids[i].equals(""))
					{
						stridsinfo+="'"+arraygxids[i]+"',";
					}
				}
				if (stridsinfo.length()>0){
					stridsinfo = stridsinfo.substring(0,stridsinfo.length()-1);
				}
				//strWhere = " and PIPENO in ("+stridsinfo+")";
				strWhere = " and VALVENO in ("+stridsinfo+")";
			}
			queryString.append(" select PRESSURELEVEL,(select wm_concat(pipelineno) " +
					"from PTEM_VALVE t2 where t1.PRESSURELEVEL = t2.PRESSURELEVEL "+strWhere+"  and rownum<100 ) as pipelinenos," +
					"count(PRESSURELEVEL) as vcount from PTEM_VALVE t1 " +
					"where PRESSURELEVEL is not null "+strWhere+" group by PRESSURELEVEL");
			Query query = getSession().createSQLQuery(queryString.toString());
			return query.list();
		}
		else{
			String gxids = "";
			String strWhere = "";
			if (filterMap.get("gxids")!=null){
				gxids = filterMap.get("gxids").toString().replace("gx", "").replace("all", "");
			}
			if (!gxids.equals("")){
				String stridsinfo = "";
				String[] arraygxids = gxids.split(",");
				for(int i=0;i<arraygxids.length;i++){
					if (!arraygxids[i].equals(""))
					{
						stridsinfo+="'"+arraygxids[i]+"',";
					}
				}
				if (stridsinfo.length()>0){
					stridsinfo = stridsinfo.substring(0,stridsinfo.length()-1);
				}
				strWhere = " and pipelineno in ("+stridsinfo+")";
			}
			queryString.append(" select PRESSURELEVEL,(select wm_concat(pipelineno) " +
					"from PTEM_PIPELINE t2 where t1.PRESSURELEVEL = t2.PRESSURELEVEL "+strWhere+"  ) as pipelinenos," +
					"count(PRESSURELEVEL) as vcount from PTEM_PIPELINE t1 " +
					"where PRESSURELEVEL is not null "+strWhere+" group by PRESSURELEVEL");
			Query query = getSession().createSQLQuery(queryString.toString());
			return query.list();
		}
	}
	
	public PageResult tongjiYunxingdw(Map filterMap){
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		String fieldname = filterMap.get("fieldname").toString();
		if (fieldname.equals("zhanxiangyxdw")){
			String zxids = "";
			String strWhere = "";
			if (filterMap.get("zxids")!=null){
				zxids = filterMap.get("zxids").toString().replace("zx", "").replace("all", "");
			}
			if (!zxids.equals("")){
				String stridsinfo = "";
				String[] arraygxids = zxids.split(",");
				for(int i=0;i<arraygxids.length;i++){
					if (!arraygxids[i].equals(""))
					{
						stridsinfo+="'"+arraygxids[i]+"',";
					}
				}
				if (stridsinfo.length()>0){
					stridsinfo = stridsinfo.substring(0,stridsinfo.length()-1);
				}
				strWhere = " and pipeno in ("+stridsinfo+")";
			}
			queryString.append(" select MANAGEUNIT,(select wm_concat(pipelineno) " +
					"from PTEM_STATION t2 where t1.MANAGEUNIT = t2.MANAGEUNIT "+strWhere+"  and rownum<100 ) as pipelinenos," +
					"count(MANAGEUNIT) as vcount from PTEM_STATION t1 " +
					"where MANAGEUNIT is not null "+strWhere+" group by MANAGEUNIT");
			countString.append("select count(*) from ("+queryString+") t ");
			return searchBySQL(countString.toString(),queryString.toString(),filterMap);
		}
		else if (fieldname.equals("famenyxdw")){
			String fmids = "";
			String strWhere = "";
			if (filterMap.get("fmids")!=null){
				fmids = filterMap.get("fmids").toString().replace("all", "");
			}
			if (!fmids.equals("")){
				String stridsinfo = "";
				String[] arraygxids = fmids.split(",");
				for(int i=0;i<arraygxids.length;i++){
					if (!arraygxids[i].equals(""))
					{
						stridsinfo+="'"+arraygxids[i]+"',";
					}
				}
				if (stridsinfo.length()>0){
					stridsinfo = stridsinfo.substring(0,stridsinfo.length()-1);
				}
				strWhere = " and PIPENO in ("+stridsinfo+")";
			}
			queryString.append(" select PRESSURELEVEL,(select wm_concat(pipelineno) " +
					"from PTEM_VALVE t2 where t1.PRESSURELEVEL = t2.PRESSURELEVEL "+strWhere+"  and rownum<100 ) as pipelinenos," +
					"count(PRESSURELEVEL) as vcount from PTEM_VALVE t1 " +
					"where PRESSURELEVEL is not null "+strWhere+" group by PRESSURELEVEL");
			countString.append("select count(*) from ("+queryString+") t ");
			return searchBySQL(countString.toString(),queryString.toString(),filterMap);
		}
		else{
			String gxids = "";
			String strWhere = "";
			if (filterMap.get("gxids")!=null){
				gxids = filterMap.get("gxids").toString().replace("gx", "").replace("all", "");
			}
			if (!gxids.equals("")){
				String stridsinfo = "";
				String[] arraygxids = gxids.split(",");
				for(int i=0;i<arraygxids.length;i++){
					if (!arraygxids[i].equals(""))
					{
						stridsinfo+="'"+arraygxids[i]+"',";
					}
				}
				if (stridsinfo.length()>0){
					stridsinfo = stridsinfo.substring(0,stridsinfo.length()-1);
				}
				strWhere = " and pipelineno in ("+stridsinfo+")";
			}
			queryString.append(" select MANAGEDEPARTMENT,(select wm_concat(pipelineno) " +
					"from PTEM_PIPELINE t2 where t1.MANAGEDEPARTMENT = t2.MANAGEDEPARTMENT "+strWhere+"  and rownum<100 ) as pipelinenos," +
					"count(MANAGEDEPARTMENT) as vcount from PTEM_PIPELINE t1 " +
					"where MANAGEDEPARTMENT is not null "+strWhere+" group by MANAGEDEPARTMENT");
			countString.append("select count(*) from ("+queryString+") t ");
			return searchBySQL(countString.toString(),queryString.toString(),filterMap);
			
		}
	}
	
	public List tongjiYunxingdwpic(Map filterMap){
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		String fieldname = filterMap.get("fieldname").toString();
		if (fieldname.equals("zhanxiangyxdw")){
			String zxids = "";
			String strWhere = "";
			if (filterMap.get("zxids")!=null){
				zxids = filterMap.get("zxids").toString().replace("zx", "").replace("all", "");
			}
			if (!zxids.equals("")){
				String stridsinfo = "";
				String[] arraygxids = zxids.split(",");
				for(int i=0;i<arraygxids.length;i++){
					if (!arraygxids[i].equals(""))
					{
						stridsinfo+="'"+arraygxids[i]+"',";
					}
				}
				if (stridsinfo.length()>0){
					stridsinfo = stridsinfo.substring(0,stridsinfo.length()-1);
				}
				strWhere = " and pipeno in ("+stridsinfo+")";
			}
			queryString.append(" select MANAGEUNIT,(select wm_concat(pipelineno) " +
					"from PTEM_STATION t2 where t1.MANAGEUNIT = t2.MANAGEUNIT "+strWhere+"  and rownum<100 ) as pipelinenos," +
					"count(MANAGEUNIT) as vcount from PTEM_STATION t1 " +
					"where MANAGEUNIT is not null "+strWhere+" group by MANAGEUNIT");
			Query query = getSession().createSQLQuery(queryString.toString());
			return query.list();
		}
		else if (fieldname.equals("famenyxdw")){
			String fmids = "";
			String strWhere = "";
			if (filterMap.get("fmids")!=null){
				fmids = filterMap.get("fmids").toString().replace("all", "");
			}
			if (!fmids.equals("")){
				String stridsinfo = "";
				String[] arraygxids = fmids.split(",");
				for(int i=0;i<arraygxids.length;i++){
					if (!arraygxids[i].equals(""))
					{
						stridsinfo+="'"+arraygxids[i]+"',";
					}
				}
				if (stridsinfo.length()>0){
					stridsinfo = stridsinfo.substring(0,stridsinfo.length()-1);
				}
				strWhere = " and PIPENO in ("+stridsinfo+")";
			}
			queryString.append(" select PRESSURELEVEL,(select wm_concat(pipelineno) " +
					"from PTEM_VALVE t2 where t1.PRESSURELEVEL = t2.PRESSURELEVEL "+strWhere+"  and rownum<100 ) as pipelinenos," +
					"count(PRESSURELEVEL) as vcount from PTEM_VALVE t1 " +
					"where PRESSURELEVEL is not null "+strWhere+" group by PRESSURELEVEL");
			countString.append("select count(*) from ("+queryString+") t ");
			Query query = getSession().createSQLQuery(queryString.toString());
			return query.list();
		}
		else{
			String gxids = "";
			String strWhere = "";
			if (filterMap.get("gxids")!=null){
				gxids = filterMap.get("gxids").toString().replace("gx", "").replace("all", "");
			}
			if (!gxids.equals("")){
				String stridsinfo = "";
				String[] arraygxids = gxids.split(",");
				for(int i=0;i<arraygxids.length;i++){
					if (!arraygxids[i].equals(""))
					{
						stridsinfo+="'"+arraygxids[i]+"',";
					}
				}
				if (stridsinfo.length()>0){
					stridsinfo = stridsinfo.substring(0,stridsinfo.length()-1);
				}
				strWhere = " and pipeno in ("+stridsinfo+")";
			}
			queryString.append(" select MANAGEDEPARTMENT,(select wm_concat(pipelineno) " +
					"from PTEM_PIPELINE t2 where t1.MANAGEDEPARTMENT = t2.MANAGEDEPARTMENT "+strWhere+"  and rownum<100 ) as pipelinenos," +
					"count(MANAGEDEPARTMENT) as vcount from PTEM_PIPELINE t1 " +
					"where MANAGEDEPARTMENT is not null "+strWhere+" group by MANAGEDEPARTMENT");
			Query query = getSession().createSQLQuery(queryString.toString());
			return query.list();
		}
	}
	
	public PageResult tongjiTezhengd(Map filterMap){
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		String fieldname = filterMap.get("fieldname").toString();
		
		String gxids = "";
		String strWhere = "";
		if (filterMap.get("gxids")!=null){
			gxids = filterMap.get("gxids").toString().replace("gx", "").replace("all", "");
		}
		if (!gxids.equals("")){
			String stridsinfo = "";
			String[] arraygxids = gxids.split(",");
			for(int i=0;i<arraygxids.length;i++){
				if (!arraygxids[i].equals(""))
				{
					stridsinfo+="'"+arraygxids[i]+"',";
				}
			}
			if (stridsinfo.length()>0){
				stridsinfo = stridsinfo.substring(0,stridsinfo.length()-1);
			}
			strWhere = " and t.pipelineno in ("+stridsinfo+")";
		}
		
		queryString.append(" select distinct pipelineno");
		//queryString.append(" select pipelineno");
		String[] fds = fieldname.split(",");
		for(int i=0;i<fds.length;i++){
			queryString.append(getTezhengdSql(Integer.parseInt(fds[i])));
			queryString.append(" as item"+i);
		}
		queryString.append(" from PTEM_PIPEPOINT t where t.pipelineno is not null "+strWhere);
		countString.append("select count(*) from ("+queryString+") t ");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	public String getTezhengdSql(int index){
		String strSql = "";
		if (index==1){
			strSql = ",(select count(*) from PTEM_PIPEPOINT where t.pipelineno=pipelineno and  type='绝缘接头' ) ";
		}
		else if (index==2){
			strSql = ",(select count(*) from PTEM_PIPEPOINT where t.pipelineno=pipelineno and  type='连头' ) ";
		}
		else if (index==3){
			strSql = ",(select count(*) from PTEM_PIPEPOINT where t.pipelineno=pipelineno and  type='弯头' ) ";
		}
		else if (index==4){
			strSql = ",(select count(*) from PTEM_PIPEPOINT where t.pipelineno=pipelineno and  type='变径' ) ";
		}
		else if (index==5){
			strSql = ",(select count(*) from PTEM_PIPEPOINT where t.pipelineno=pipelineno and  type='标志桩' ) ";
		}
		else if (index==6){
			strSql = ",(select count(*) from PTEM_PIPEPOINT where t.pipelineno=pipelineno and  type='标志钉' ) ";
		}
		else if (index==7){
			strSql = ",(select count(*) from PTEM_PIPEPOINT where t.pipelineno=pipelineno and  type='钢塑转换' ) ";
		}
		else if (index==8){
			strSql = ",(select count(*) from PTEM_PIPEPOINT where t.pipelineno=pipelineno and  type='凝水缸' ) ";
		}
		else if (index==9){
			strSql = ",(select count(*) from PTEM_PIPEPOINT where t.pipelineno=pipelineno and  type='焊缝' ) ";
		}
		else if (index==10){
			strSql = ",(select count(*) from PTEM_PIPEPOINT where t.pipelineno=pipelineno and  type='信息球' ) ";
		}
		else if (index==11){
			strSql = ",(select count(*) from PTEM_PIPEPOINT where t.pipelineno=pipelineno and  type='其他' ) ";
		}
		else if (index==12){
			strSql = ",(select count(*) from PTEM_POINT_TEE where t.pipelineno=pipelineno ) ";
		}
		else if (index==13){
			strSql = ",(select count(*) from PTEM_POINT_ANODE where t.pipelineno=pipelineno ) ";
		}
		else if (index==14){
			strSql = ",(select count(*) from PTEM_POINT_POLE where t.pipelineno=pipelineno ) ";
		}
		else if (index==15){
			strSql = ",(select count(*) from PTEM_POINT_DRAINAGE where t.pipelineno=pipelineno ) ";
		}
		else if (index==16){
			strSql = ",(select count(*) from PTEM_POINT_CROSSING where t.pipelineno=pipelineno ) ";
		}
		else if (index==17){
			strSql = ",(select count(*) from PTEM_POINT_CASING where t.pipelineno=pipelineno ) ";
		}
		return strSql;
	}
//	public String getTezhengdSql(int index){
//		String strSql = "";
//		if (index==1){
//			strSql = ",(select count(*) from PTEM_PIPEPOINT where t.pipelineno=pipelineno and  pointtype='绝缘接头' ) ";
//		}
//		else if (index==2){
//			strSql = ",(select count(*) from PTEM_PIPEPOINT where t.pipelineno=pipelineno and  pointtype='连头' ) ";
//		}
//		else if (index==3){
//			strSql = ",(select count(*) from PTEM_PIPEPOINT where t.pipelineno=pipelineno and  pointtype='弯头' ) ";
//		}
//		else if (index==4){
//			strSql = ",(select count(*) from PTEM_PIPEPOINT where t.pipelineno=pipelineno and  pointtype='变径' ) ";
//		}
//		else if (index==5){
//			strSql = ",(select count(*) from PTEM_PIPEPOINT where t.pipelineno=pipelineno and  pointtype='标志桩' ) ";
//		}
//		else if (index==6){
//			strSql = ",(select count(*) from PTEM_PIPEPOINT where t.pipelineno=pipelineno and  pointtype='标志钉' ) ";
//		}
//		else if (index==7){
//			strSql = ",(select count(*) from PTEM_PIPEPOINT where t.pipelineno=pipelineno and  pointtype='钢塑转换' ) ";
//		}
//		else if (index==8){
//			strSql = ",(select count(*) from PTEM_PIPEPOINT where t.pipelineno=pipelineno and  pointtype='凝水缸' ) ";
//		}
//		else if (index==9){
//			strSql = ",(select count(*) from PTEM_PIPEPOINT where t.pipelineno=pipelineno and  pointtype='焊缝' ) ";
//		}
//		else if (index==10){
//			strSql = ",(select count(*) from PTEM_PIPEPOINT where t.pipelineno=pipelineno and  pointtype='信息球' ) ";
//		}
//		else if (index==11){
//			strSql = ",(select count(*) from PTEM_PIPEPOINT where t.pipelineno=pipelineno and  pointtype='其他' ) ";
//		}
//		else if (index==12){
//			strSql = ",(select count(*) from PTEM_POINT_TEE where t.pipelineno=pipelineno ) ";
//		}
//		else if (index==13){
//			strSql = ",(select count(*) from PTEM_POINT_ANODE where t.pipelineno=pipelineno ) ";
//		}
//		else if (index==14){
//			strSql = ",(select count(*) from PTEM_POINT_POLE where t.pipelineno=pipelineno ) ";
//		}
//		else if (index==15){
//			strSql = ",(select count(*) from PTEM_POINT_DRAINAGE where t.pipelineno=pipelineno ) ";
//		}
//		else if (index==16){
//			strSql = ",(select count(*) from PTEM_POINT_CROSSING where t.pipelineno=pipelineno ) ";
//		}
//		else if (index==17){
//			strSql = ",(select count(*) from PTEM_POINT_CASING where t.pipelineno=pipelineno ) ";
//		}
//		return strSql;
//	}
	
	public List tongjiTezhengdexp(Map filterMap){
		StringBuffer queryString = new StringBuffer();
		String fieldname = filterMap.get("fieldname").toString();
		
		String gxids = "";
		String strWhere = "";
		if (filterMap.get("gxids")!=null){
			gxids = filterMap.get("gxids").toString().replace("gx", "").replace("all", "");
		}
		if (!gxids.equals("")){
			String stridsinfo = "";
			String[] arraygxids = gxids.split(",");
			for(int i=0;i<arraygxids.length;i++){
				if (!arraygxids[i].equals(""))
				{
					stridsinfo+="'"+arraygxids[i]+"',";
				}
			}
			if (stridsinfo.length()>0){
				stridsinfo = stridsinfo.substring(0,stridsinfo.length()-1);
			}
			strWhere = " and t.pipelineno in ("+stridsinfo+")";
		}
		queryString.append(" select pipelineno");
		String[] fds = fieldname.split(",");
		for(int i=0;i<fds.length;i++){
			queryString.append(getTezhengdSql(Integer.parseInt(fds[i])));
			queryString.append(" as item"+i);
		}
		queryString.append(" from PTEM_PIPEPOINT t where t.pipelineno is not null "+strWhere);
		Query query = getSession().createSQLQuery(queryString.toString());
		return query.list();
	}
	
	public PageResult tongjiLishisj(Map filterMap){
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		String fieldname = filterMap.get("fieldname").toString();
		
		String gxids = "";
		String strWhere = "";
		if (filterMap.get("gxids")!=null){
			gxids = filterMap.get("gxids").toString().replace("gx", "").replace("all", "");
		}
		if (!gxids.equals("")){
			String stridsinfo = "";
			String[] arraygxids = gxids.split(",");
			for(int i=0;i<arraygxids.length;i++){
				if (!arraygxids[i].equals(""))
				{
					stridsinfo+="'"+arraygxids[i]+"',";
				}
			}
			if (stridsinfo.length()>0){
				stridsinfo = stridsinfo.substring(0,stridsinfo.length()-1);
			}
			strWhere = " and t.pipelineno in ("+stridsinfo+")";
		}
		//queryString.append(" select pipelineno");
		queryString.append(" select distinct pipelineno");
		String[] fds = fieldname.split(",");
		for(int i=0;i<fds.length;i++){
			queryString.append(getLishisjSql(Integer.parseInt(fds[i])));
			queryString.append(" as item"+i);
		}
		queryString.append(" from PTEM_PIPEPOINT t where t.pipelineno is not null "+strWhere);
		countString.append("select count(*) from ("+queryString+") t ");
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	
	public String getLishisjSql(int index){
		String strSql = "";
		if (index==1){
			strSql = ",(select count(*) from PTEM_EXCEPTION where t.pipelineno=pipelineno ) ";
		}
		else if (index==2){
			strSql = ",(select count(*) from PTEM_SPECIAL where t.pipelineno=pipelineno  ) ";
		}
		else if (index==3){
			strSql = ",(select count(*) from PTEM_VIOLATION where t.pipelineno=pipelineno  ) ";
		}
		else if (index==4){
			strSql = ",(select count(*) from PTEM_EMERGENCY where t.pipelineno=pipelineno ) ";
		}
		else if (index==5){
			strSql = ",(select count(*) from PTEM_LEAKPOINT where t.pipelineno=pipelineno  ) ";
		}
		else if (index==6){
			strSql = ",(select count(*) from PTEM_OPERATIONS where t.pipelineno=pipelineno  ) ";
		}
		else if (index==7){
			strSql = ",(select count(*) from PTEM_FITTING where t.pipelineno=pipelineno ) ";
		}
		return strSql;
	}
	
	public List tongjiLishisjexp(Map filterMap){
		StringBuffer queryString = new StringBuffer();
		String fieldname = filterMap.get("fieldname").toString();
		
		String gxids = "";
		String strWhere = "";
		if (filterMap.get("gxids")!=null){
			gxids = filterMap.get("gxids").toString().replace("gx", "").replace("all", "");
		}
		if (!gxids.equals("")){
			String stridsinfo = "";
			String[] arraygxids = gxids.split(",");
			for(int i=0;i<arraygxids.length;i++){
				if (!arraygxids[i].equals(""))
				{
					stridsinfo+="'"+arraygxids[i]+"',";
				}
			}
			if (stridsinfo.length()>0){
				stridsinfo = stridsinfo.substring(0,stridsinfo.length()-1);
			}
			strWhere = " and t.pipelineno in ("+stridsinfo+")";
		}
		queryString.append(" select pipelineno");
		String[] fds = fieldname.split(",");
		for(int i=0;i<fds.length;i++){
			queryString.append(getLishisjSql(Integer.parseInt(fds[i])));
			queryString.append(" as item"+i);
		}
		queryString.append(" from PTEM_PIPEPOINT t where t.pipelineno is not null "+strWhere);
		Query query = getSession().createSQLQuery(queryString.toString());
		return query.list();
	}
	
	public PageResult tongjiDongtaisj(Map filterMap){
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		String fieldname = filterMap.get("fieldname").toString();
		String gxids = "";
		String strWhere = "";
		if (filterMap.get("gxids")!=null){
			gxids = filterMap.get("gxids").toString().replace("gx", "").replace("all", "");
		}
		if (!gxids.equals("")){
			String stridsinfo = "";
			String[] arraygxids = gxids.split(",");
			for(int i=0;i<arraygxids.length;i++){
				if (!arraygxids[i].equals(""))
				{
					stridsinfo+="'"+arraygxids[i]+"',";
				}
			}
			if (stridsinfo.length()>0){
				stridsinfo = stridsinfo.substring(0,stridsinfo.length()-1);
			}
			strWhere = " and pipelineno in ("+stridsinfo+")";
		}
		if (fieldname.equals("防腐层状况统计")){
			queryString.append(" select RISOVALUELEVEL,(select wm_concat(pipelineno) " +
					"from PTEM_COATING_RISO_EVALUATE t2 where t1.RISOVALUELEVEL = t2.RISOVALUELEVEL "+strWhere+"  ) as pipelinenos," +
					"count(RISOVALUELEVEL) as vcount from PTEM_COATING_RISO_EVALUATE t1 " +
					"where RISOVALUELEVEL is not null "+strWhere+" group by RISOVALUELEVEL");
			countString.append("select count(*) from ("+queryString+") t ");
		}
		else if (fieldname.equals("阴保状况统计")){
			queryString.append(" select EVALUATERESULT,(select wm_concat(pipelineno) " +
					"from PTEM_CP_EVALUATE t2 where t1.EVALUATERESULT = t2.EVALUATERESULT "+strWhere+"  ) as pipelinenos," +
					"count(EVALUATERESULT) as vcount from PTEM_CP_EVALUATE t1 " +
					"where EVALUATERESULT is not null "+strWhere+" group by EVALUATERESULT");
			countString.append("select count(*) from ("+queryString+") t ");
		}
		else if (fieldname.equals("埋深统计")){
			queryString.append(" select PIPEDEPTH,(select wm_concat(pipelineno) " +
					"from PTEM_SOILCORROSION t2 where t1.PIPEDEPTH = t2.PIPEDEPTH "+strWhere+"  ) as pipelinenos," +
					"count(PIPEDEPTH) as vcount from PTEM_SOILCORROSION t1 " +
					"where PIPEDEPTH is not null "+strWhere+" group by PIPEDEPTH");
			countString.append("select count(*) from ("+queryString+") t ");
		}
		
		return searchBySQL(countString.toString(),queryString.toString(),filterMap);
	}
	
	public List tongjiDongtaisjpic(Map filterMap){
		StringBuffer countString = new StringBuffer();
		StringBuffer queryString = new StringBuffer();
		String fieldname = filterMap.get("fieldname").toString();
		String gxids = "";
		String strWhere = "";
		if (filterMap.get("gxids")!=null){
			gxids = filterMap.get("gxids").toString().replace("gx", "").replace("all", "");
		}
		if (!gxids.equals("")){
			String stridsinfo = "";
			String[] arraygxids = gxids.split(",");
			for(int i=0;i<arraygxids.length;i++){
				if (!arraygxids[i].equals(""))
				{
					stridsinfo+="'"+arraygxids[i]+"',";
				}
			}
			if (stridsinfo.length()>0){
				stridsinfo = stridsinfo.substring(0,stridsinfo.length()-1);
			}
			strWhere = " and pipelineno in ("+stridsinfo+")";
		}
		if (fieldname.equals("防腐层状况统计")){
			queryString.append(" select RISOVALUELEVEL,(select wm_concat(pipelineno) " +
					"from PTEM_COATING_RISO_EVALUATE t2 where t1.RISOVALUELEVEL = t2.RISOVALUELEVEL "+strWhere+"  ) as pipelinenos," +
					"count(RISOVALUELEVEL) as vcount from PTEM_COATING_RISO_EVALUATE t1 " +
					"where RISOVALUELEVEL is not null "+strWhere+" group by RISOVALUELEVEL");
		}
		else if (fieldname.equals("阴保状况统计")){
			queryString.append(" select EVALUATERESULT,(select wm_concat(pipelineno) " +
					"from PTEM_CP_EVALUATE t2 where t1.EVALUATERESULT = t2.EVALUATERESULT "+strWhere+"  ) as pipelinenos," +
					"count(EVALUATERESULT) as vcount from PTEM_CP_EVALUATE t1 " +
					"where EVALUATERESULT is not null "+strWhere+" group by EVALUATERESULT");
		}
		else{
			queryString.append(" select PIPEDEPTH,(select wm_concat(pipelineno) " +
					"from PTEM_SOILCORROSION t2 where t1.PIPEDEPTH = t2.PIPEDEPTH "+strWhere+"  ) as pipelinenos," +
					"count(PIPEDEPTH) as vcount from PTEM_SOILCORROSION t1 " +
					"where PIPEDEPTH is not null "+strWhere+" group by PIPEDEPTH");
		}
		Query query = getSession().createSQLQuery(queryString.toString());
		return query.list();
	}
	
}
